<div class="operateBox">
    <h2>文件</h2>
</div>

<div class="left">
    <div id="dirList" class="dir-tree"><p class="active" i_ID=""><span class="fl-r noVis icon-16-reset button_16"></span><b class="hand has"></b><span class="title">根目录</span></p></div>
</div>

<div class="right">
  <div class="navBox">
    <div id="fli_nav" class="fl-l"></div>
    <a id="b_found_dir" class="icon-16-category">创建目录</a> 
    <div id="uploadD" class="fl-r"></div>
  </div>
  <div class="lv-r" id="dataList">
    <div class="l-head"><span class="name sl-ah">名称</span><span class="size">大小</span><span class="time">上传时间</span></div>
    <div id="fileList"></div>
    <?php if(isset($_GET['select'])) echo '<p><input type="button" class="submit" value="确定选择" onclick="qu_selected()" /></p>'?>
  </div>
</div>
<div class="cl_l"></div>


<?php html::pushHead('file/1.css||fileUpload.js');?>
<script type="text/javascript">
var dTA = Table_Ad.init('#dataList',{u_del:'?u=cfile\\a-fdel&f='});

// upload
var FU = FileUpload('#uploadD');
FU.callFun = function(res){
    if(this.dir==''){
        var n=res.path.lastIndexOf('/'), d = res.path.substring(0,n),b = box(''),
        s = $('<span>操作成功，<a>查看上传文件</a></span>')
        s.find('a').click(function(){getFL(d);b.close();});
        return b.set(s);
    }
    if (!res.type){
        var n=res.name.lastIndexOf('.');
        res.type = res.name.substring(n+1);
    }
    showFile(mergeConf({ctime:''},res));
}
$('#b_found_dir').click(function(){
  var a  = prompt('创建目录:'), dir = FU.dir;
  if(a){
	$.post('?u=cfile\\a-ffoundDir&dir='+dir, 'name='+a, function(r){
		if(checAjaxRe(r))
			showFile({ctime:'',name:a,type:'folder',path:dir+'/'+a});
	});
  }
});

// 文件
var flO = $('#fileList');
function getFL(dir){
	setLoading(flO[0]);
	$.get('?u=cfile\\a-flist&dir='+dir ,'' ,function(r){
        flO.html('');
		if(checAjaxRe(r)){
            FU.dir = dir;
			for(var i=0,l=r.res.length; i<l;i++ )showFile(r.res[i]);
		 }
         
        // nav
        var s = '&raquo; &nbsp;<a onclick="getFL(\'\')">根目录</a>', nav = dir.split('/'),n, d='';
        for(var i=0,l=nav.length; i<l; i++){
            n = nav[i];
            d += '/' + n;
            if (n!='')s += '&nbsp; &raquo; &nbsp;<a onclick="getFL(\''+ d +'\')">'+ n +'</a>';
        }
        $('#fli_nav').html(s);
	});
}
function showFile(res){
  var size= res.type=='folder'?'':format_fileSize(res.size),str = '<div class="sl-i" i_ID="'+encodeURIComponent(res.path) +'"><span class="sl-h name"><span class="ico ico-'+res.type+'">';
  str += '</span>'+ res.name+'</span><span class="size">'+ size+'</span><span class="time">'+ res.ctime+'</span>\n\
          <span><a class="icon-16-delete button_16" onclick="dTA.delRow()"></a></span>\n\
        </div>';
  var d = $(str).appendTo(flO).data(res);
  d.find('.name').dblclick({res:res},function(e){
	  var d = e.data.res;
	  d.type=='folder' ?getFL(d.path) :w_open(ROOT_URL + '?u=cimg\\b&f='+encodeURIComponent(d.path) );   
  	});
}

// 目录
var dirLO = $('#dirList');
dirTree_li(dirLO, '?u=cfile\\a-fdir&dir=');
$('p', dirLO).live('click', function(){getFL($(this).attr('i_ID'));});
dirLO.find('p:first').click();

// selected
<?php if(isset($_GET['select'])){?>
function qu_selected()
{
	var  wp = window.opener,dA =[], slA=$('#dataList .ui-selected');
	if (slA.length<1)
		return alert(language._('qing xian xuan ze'));
	slA.each(function(){
		var a = $(this);
		if(a.find('.ico-folder').length==0){
            var d = a.data();
			dA.push(d);
        }
	});
	if(dA.length<1)
		return alert('请选择合法文件');

    <?php $g = $_GET; if ($g['callFun']){if($fun=realFunName($g['callFun'])) echo 'wp.'.$fun.'(dA);';
    }elseif($g['set_obj']){ 
        if($g['set_val']=='img'){
            $_a = '';
            if($g['set_w'])
               $_a .='&w='. intval($g['set_w']);
            if($g['set_h'])
               $_a .='&h='. intval($g['set_h']);
            $set_v = 'ROOT_URL + "?u=cimg\\\\b&f="+ encodeURIComponent(dA[0].path) + "'.$_a.'"';
		}elseif($g['set_val']=='id'){
            $set_v = 'dA[0].path';
		}else
            $set_v = 'ROOT_URL + "?u=cfile\\\\b&f="+ encodeURIComponent(dA[0].path)';
        echo 'wp.$_obj("'. realFunName($g['set_obj']) .'").value='. $set_v .'; ';
    }elseif (isset($g['CKEditorFuncNum'])){?>
    wp.CKEDITOR.tools.callFunction('<?php echo intval($g['CKEditorFuncNum'])?>', ROOT_URL +'?u=cimg\\b&f='+ encodeURIComponent(dA[0].path) );
	<?php }?>
	
	window.close();
}
<?php 
echo $g['select']=='M' && $g['callFun'] ?'dTA.creSelect();' :'dTA.singleSelect();';
}?>
</script>
